package com.tanhua.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.TanhuaServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 杰哥不要啦~
 * @date 2021/10/29
 */
@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaServer tanhuaServer;


    //查询今日家人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        TodayBest vo = tanhuaServer.todayBest();
        return ResponseEntity.ok(vo);
    }

    //分页查询推荐好友列表
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto){
        PageResult pr = tanhuaServer.recommendation(dto);
        return ResponseEntity.ok(pr);
    }

    //查询家人
    @GetMapping("{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id")Long userId){
        TodayBest best = tanhuaServer.personalInfo(userId);
        return ResponseEntity.ok(best);
    }

    //查询陌生人问题
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String questions = tanhuaServer.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    //回复陌生人问题
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map){
        //前端传递的userId:是Integer类型的
        String id = map.get("userId").toString();
        Long userId = Long.valueOf(id);
        String reply = map.get("reply").toString();
        tanhuaServer.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    //cha探花-推荐用户列表
    @GetMapping("/cards")
    public ResponseEntity queryCardsList(){
        List<TodayBest> list = this.tanhuaServer.queryCardsList();
        return ResponseEntity.ok(list);
    }
    /**
     * 喜欢
     */
    @GetMapping("{id}/love")
    public ResponseEntity<Void> likeUser(@PathVariable("id") Long likeUserId) {
        this.tanhuaServer.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 不喜欢
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLikeUser(@PathVariable("id") Long likeUserId) {
        this.tanhuaServer.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }
}
